package com.financing.task.agent;
import java.util.Random;

import org.apache.log4j.Logger;

import com.financing.common.CONST;
import com.financing.model.Data;
import com.financing.service.user.UserService;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;

/**
 * 自动分配客服任务
 * @author 无处不在的二叔
 */
public class AutoAllotTask implements Runnable{

	private UserService user = new UserService();
    private static final Logger logger = Logger.getLogger(AutoAllotTask.class);
    
	@Override 
	@Before(Tx.class)
	public void run() {
		logger.error("自动分配客服开始！");		
		Random random = new Random();	
		String[] agents = CONST.find("ALLOT_AGENTS").split(",");
		user.list(1, 999, Data.putStr("agent_id","0")).getList().forEach(n->{
			n.setAgentId(Integer.valueOf(agents[random.nextInt(agents.length)])).update();
		});
	}
}
